package com.yycx.module.bus.provider.service.hy;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.module.bus.client.entity.hy.BusHyorderReturn;
import com.yycx.common.mybatis.base.service.IBaseService;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.vo.OrderCustomReturn;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 回款明细 接口
 *
 * @author flyme
 * @date 2023-11-23
 */
public interface BusHyorderReturnService extends IBaseService<BusHyorderReturn> {


    /**
     * 统计回款信息
     *
     * @param settleIds
     * @return
     */
    EntityMap totalReturnAmountInfo(String settleIds);


    /**
     * 查询订单明细
     *
     * @param selectIds
     * @return
     */
    List<BusHyorderReturn> selectByIds(String[] selectIds);

    /**
     * 添加票折
     *
     * @param orderDetailsReturnId
     * @param saleAmount
     * @return
     */
    ResultBody addDiscountDetails(String orderDetailsReturnId, BigDecimal saleAmount);

    /**
     * 更新超期金额
     * @param orderDetailsReturnId
     * @param settleOverDay
     * @param settleOverPrice
     * @param overDateAmount
     * @return
     */
    Boolean updateOverAmount(String orderDetailsReturnId,Integer settleOverDay ,BigDecimal settleOverPrice, BigDecimal overDateAmount);

    /**
     * 查询订单明细
     *
     * @param returnId
     * @return
     */
    List<EntityMap> selectByReturnId(Long returnId);


    /**
     * 拆分订单
     *
     * @param bocr
     * @return
     */
    ResultBody chaiFen(OrderCustomReturn bocr);

    /**
     * 拆分订单
     *
     * @param bocr
     * @param orderDetails
     * @return
     */
    BusHyorderReturn chaiFenByParent(OrderCustomReturn bocr, BusHyorderReturn orderDetails);


    /**
     * 把比例计算回款记录
     *
     * @param hyorderReturn
     * @param ratio
     */
    void computeAmount(BusHyorderReturn hyorderReturn, BigDecimal ratio);

    /**
     * 更新回款ID
     *
     * @param payment
     * @param selectIds
     * @return
     */
    Boolean updateReturnId(BusPayment payment, String selectIds);

    /**
     * 清空返款信息
     *
     * @param returnId
     * @return
     */
    Boolean clearHuiKuanInfo(Serializable returnId);

    /**
     * 更新认款
     *
     * @param payment
     * @return
     */
    Boolean updateReturnInfo(BusPayment payment);

    /**
     * 撤销拆分
     *
     * @param orderDetailsReturnId
     * @return
     */
    ResultBody cancelChaiFen(String orderDetailsReturnId);


    /**
     * 计算渠道商结算金额
     *
     * @param settleIds
     * @param settleType
     * @return
     */
    BigDecimal totalSettleApplyAmount(String settleIds, Integer settleType);

    /**
     * 计算部门结算金额
     *
     * @param settleIds
     * @return
     */
    EntityMap totalDeptSettleApplyAmount(String settleIds);


    /**
     * 统计所选数据中渠道商结算人数量
     *
     * @param settleIds
     * @param settleType
     * @return
     */
    EntityMap countSettleManId(String settleIds, Integer settleType);

    /**
     * 关联部门结算申请ID
     *
     * @param paymentId
     * @param selectIds
     * @return
     */
    Boolean updateDeptSettleApplyId(Long paymentId, String selectIds);


    /**
     * 关联结算申请ID
     *
     * @param paymentId
     * @param selectIds
     * @param settleType
     * @return
     */
    Boolean updateSettleApplyId(Long paymentId, List<Long> selectIds, Integer settleType);


    /**
     * 清空结算申请ID
     *
     * @param paymentId
     * @param settleType
     * @return
     */
    Boolean clearSettleApplyId(Serializable paymentId, Integer settleType);

    /**
     * 清空部门结算申请ID
     *
     * @param paymentId
     * @return
     */
    Boolean clearDeptSettleApplyId(Serializable paymentId);

    /**
     * 清空结算申请ID
     *
     * @param orderDetailsReturnId
     * @param settleType
     * @return
     */
    Boolean clearSettleApplyId(Long orderDetailsReturnId, Integer settleType);

    /**
     * 查询回款明细
     *
     * @param orderDetailsId
     * @return
     */
    List<BusHyorderReturn> getByOrderDetailsId(String orderDetailsId);

    /**
     * 查询退款明细
     *
     * @param orderId
     * @return
     */
    List<BusHyorderReturn> selectByOrderId(String orderId);

    /**
     * 查询退款明细
     *
     * @param orderId
     * @return
     */
    List<EntityMap> selectMapByOrderId(String orderId);


    /**
     * 更新回款状态
     *
     * @param orderDetailsReturnId
     * @return
     */
    Boolean updateReturnState(Long orderDetailsReturnId);

    /**
     * 更新开票信息
     *
     * @param payment
     * @return
     */
    Boolean updateInvoice(BusPayment payment);

    /**
     * 根据回款ID插入回款记录
     *
     * @param payment
     */
    void insertToPaymentOrderList(BusPayment payment);


    /**
     * 同步订单明细到回款表
     *
     * @param orderId
     * @return
     */
    Boolean syncOrderReturn(String orderId);

    /**
     * 同步退货定单到回款表
     *
     * @param orderId
     * @return
     */
    Boolean syncBackOrderReturn(String orderId);


    /**
     * 删除回款明细
     *
     * @param orderId
     * @return
     */
    Boolean deleteByOrderId(String orderId);


    /**
     * 按比例更新回款记录
     *
     * @param returnList
     * @param hyorderReturn
     */
    void updateBusHyorderReturn(List<BusHyorderReturn> returnList, BusHyorderReturn hyorderReturn);

    /**
     * 查询商品基本信息
     *
     * @param orderDetailsReturnId
     * @return
     */
    EntityMap selectOrderDetailsInfo(Long orderDetailsReturnId);

    /**
     * 查询回款明细
     *
     * @param settleApplyId
     * @param settleType
     * @return
     */
    List<BusHyorderReturn> getByOrderDetailsId(Long settleApplyId, Integer settleType);


    /**
     * 同步明细到回款表
     *
     * @param orderDetailsId
     * @return
     */
    ResultBody syncToReturn(String orderDetailsId);

    /**
     * 统计已退货数量
     *
     * @param orderDetailsId
     * @param orderDetailsReturnId
     * @return
     */
    EntityMap countBackNum(String orderDetailsId, Long orderDetailsReturnId);


    /**
     * 统计回款金额
     *
     * @param returnId
     * @return
     */
    BigDecimal totalReturnAmount(List<Long> returnId);

    /**
     * 统计回款金额
     *
     * @param returnId
     * @return
     */
    BigDecimal totalSaleAmount(Long returnId);


}
